<script setup lang="ts">
const route = useRoute()
const { VITE_CASINO_GAME_PAGE_SIZE } = getEnv()

const sortType = ref(EnumCasinoSortType.hot)
const pids = ref('') //供应商

const isProvider = computed(() => true) // 供应商
// 参数
const pid = computed(() =>
    isProvider.value ? route.query.pid?.toString() : void 0)
const vid = computed(() =>
    isProvider.value ? route.query.vid?.toString() : void 0)


const paramsGame = computed(() =>
({
    platform_id: pids.value,
    sort: sortType.value,
    venue_id: vid.value,
}))
// 场馆游戏
const {
    page,
    list: gameList,
    total: gameTotal,
    runAsync: runGameList,
    loading: loadingGame,
    loadMore: loadMoreGame,
} = useList(ApiMemberGameList, {
    onSuccess(res, params) {
        const paramsPids = params[0]?.platform_id ?? ''
        if (res.sums && res.sums.length > 0) {
            const arr = res.sums.map((a) => {
                return {
                    label: a.platform_name,
                    value: a.platform_id,
                    count: a.total,
                    isChecked: paramsPids.includes(a.platform_id),
                }
            })
            //emit('update:platformOptions', arr)
        }
    },
}, { page_size: VITE_CASINO_GAME_PAGE_SIZE })

function onPage(p: number) {
    page.value = p
}
// 检查场馆是否开启
function checkPlat() {
    return new Promise((resolve, reject) => {
        ApiMemberPlatformState(pid.value || vid.value || '').then((res) => {
            if (res === 1) {
                resolve(res)
            }
            else {
                i18nNavigateTo('/')
                reject(res)
            }
        })
            .catch((err) => {
                i18nNavigateTo('/')
                reject(err)
            })
    })
}

function init() {
    checkPlat().then(() => {
        runGameList(paramsGame.value)
    })

}
init()
</script>
<template>
    <BaseGameList @page="onPage" :loading="loadingGame" :data="gameList" :total="gameTotal" :page="page"
        :page-size="VITE_CASINO_GAME_PAGE_SIZE" />
</template>
<style scoped lang="scss"></style>